<template>
  <div class="main-box">
    <a-layout style="height: 100%">
      <a-layout-header class="header">
        <a-row>
          <a-col :span="12" class="heard-left">
            <img :src="imgUrl" class="heard-logo" /><span class="heard-name"
              >Vue-mobile-hxq</span
            >
          </a-col>
          <a-col :span="12" class="heard-right">
            <a-menu
              v-model:selectedKeys="headerSelectedKey"
              mode="horizontal"
              theme="light"
              :style="{ lineHeight: '64px' }"
            >
              <a-menu-item
                v-for="(item, index) in heardMenu"
                :key="index"
                @click="clickMenuTitle(index, item)"
                >{{ item }}</a-menu-item
              >
            </a-menu>
            <div>
              <img
                :src="getAssetsImages('logo-black.svg')"
                class="heard-logo"
              />
            </div>
          </a-col>
        </a-row>
      </a-layout-header>
      <a-layout class="con">
        <a-layout-sider width="260" style="background: #fff">
          <a-menu
            v-model:selectedKeys="selectedKeys2"
            v-model:openKeys="openKeys"
            mode="inline"
            :style="{ height: '100%', borderRight: 0 }"
            @click="handleClick"
            :inline-collapsed="'false'"
          >
            <!-- <a-sub-menu key="sub1">
            <template #title>
              <span>
                <user-outlined />
                文档说明
              </span>
            </template>
            <a-menu-item key="1">option1</a-menu-item>
            <a-menu-item key="2">option2</a-menu-item>
            <a-menu-item key="3">option3</a-menu-item>
            <a-menu-item key="4">option4</a-menu-item>
          </a-sub-menu>
          <a-sub-menu key="sub2">
            <template #title>
              <span>
                <laptop-outlined />
                移动端文档
              </span>
            </template>
            <a-menu-item key="5">option5</a-menu-item>
            <a-menu-item key="6">option6</a-menu-item>
            <a-menu-item key="7">option7</a-menu-item>
            <a-menu-item key="8">option8</a-menu-item>
          </a-sub-menu>
          <a-sub-menu key="sub3">
            <template #title>
              <span>
                <notification-outlined />
                PC端文档
              </span>
            </template>
            <a-menu-item key="9">option9</a-menu-item>
            <a-menu-item key="10">option10</a-menu-item>
            <a-menu-item key="11">option11</a-menu-item>
            <a-menu-item key="12">option12</a-menu-item>
          </a-sub-menu> -->
            <nav-menu :menuData="menuData"></nav-menu>
          </a-menu>
        </a-layout-sider>
        <a-layout :style="{ padding: '20px', width: '100%' }">
          <a-breadcrumb style="margin: 16px 0">
            <a-breadcrumb-item>Home</a-breadcrumb-item>
            <a-breadcrumb-item>List</a-breadcrumb-item>
            <a-breadcrumb-item>App</a-breadcrumb-item>
          </a-breadcrumb>
          <a-layout-content
            :style="{
              margin: 0,
              height: 'calc(100% - 52px)',
              position: 'relative',
            }"
          >
            <router-view class="routerDiv"></router-view>
          </a-layout-content>
        </a-layout>
      </a-layout>
    </a-layout>
  </div>
</template>
<script lang="ts" setup>
import {
  UserOutlined,
  LaptopOutlined,
  NotificationOutlined,
} from "@ant-design/icons-vue";
import img from "assets/images/logo.png";
import { ref } from "vue";
import { getAssetsImages } from "utils/imgTools";
import NavMenu from "@/components/NavMenu/menuItem.vue";
import roles from "@/router/js/data";
import { useRouter } from "vue-router";
const router = useRouter();
const imgUrl = ref(getAssetsImages("logo.png"));
//头部导航菜单及默认选中
const heardMenu = ref<string[]>(["文档说明", "移动端文档", "PC端文档"]);
const headerSelectedKey = ref<number[]>([2]);

const collapsed = ref<boolean>(false);

let menuData = ref(roles.pcdocument[0]);

console.log();
let def_path: any = window.localStorage.getItem("path");
let def_open: any = window.localStorage.getItem("open");
const selectedKeys2 = ref<any[]>([
  def_path ? def_path : menuData.value.children[0].path,
]);
const openKeys = ref<string[]>(def_open ? def_open : [menuData.value.path]);
const clickMenuTitle = (index: number, item: any) => {
  if (index == 1) {
    menuData.value = roles.mobile[0];
    selectedKeys2.value = [menuData.value.children[0].children[0].path];

    openKeys.value = [menuData.value.path, menuData.value.children[0].path];
    router.push(menuData.value.children[0].redirect);
  } else if (index == 2) {
    menuData.value = roles.pcdocument[0];
    openKeys.value = [menuData.value.path];
    console.log(menuData.value);
    
    selectedKeys2.value = [menuData.value.children[0].path];
    router.push(menuData.value.redirect);
  }
};
const handleClick = (e: any) => {
  console.log(e);

  const paths = e.keyPath.join("/");
  console.log(paths);
  window.localStorage.setItem("path", e.key);
  window.localStorage.setItem("open", e.keyPath);
  router.push({ path: paths });
};
</script>

<style lang="scss" scoped>
.main-box {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.routerDiv {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  position: absolute;
}
.header {
  background-color: #fff;
  .heard-left {
    padding-left: 70px;
    .heard-logo {
      width: 35px;
    }
    .heard-name {
      color: #000000d9;
      font-size: 18px;
      font-weight: bold;
      margin-left: 20px;
    }
  }
  .heard-right {
    display: flex;
    padding-right: 70px;
    justify-content: right;

    .heard-logo {
      width: 65px;
      margin-left: 10px;
    }
  }
}
.con {
  display: flex;
  height: calc(100% - 71px);
  margin-top: 7px;
  background-color: #fff;
  width: 100%;
}
</style>
